﻿using System;
using System.Configuration;
using KLS.PPDS.Utility.Extension;
using System.IO;

namespace KLS.PPDS.Utility
{
    public static class WebConfig
    {
        private static string GetAppSetting(string key, object defaultValue)
        {
            var value = ConfigurationManager.AppSettings[key];
            if (string.IsNullOrEmpty(value))
            {
                value = Convert.ToString(defaultValue);
            }
            return value;
        }

        public static string PublicationPackageFolder
        {
            get
            {
                var files = ConfigurationManager.AppSettings["PublicationPackageFolder"];

                if (String.IsNullOrEmpty(files))
                {
                    files = @"C:\Temp\E2A\Package";
                }
                if (!Directory.Exists(files))
                    Directory.CreateDirectory(files);
                return files;
            }
        }

        public static int ThumbnailsWidth
        {
            get
            {
                var files = ConfigurationManager.AppSettings["ThumbnailsWidth"];

                if (String.IsNullOrEmpty(files))
                {
                    files = @"65";
                }

                return Convert.ToInt32(files);
            }
        }

        public static int ThumbnailsHeight
        {
            get
            {
                var files = ConfigurationManager.AppSettings["ThumbnailsHeight"];

                if (String.IsNullOrEmpty(files))
                {
                    files = @"65";
                }

                return Convert.ToInt32(files);
            }
        }



        public static double MaxUploadFileSizeMB
        {
            get
            {
                var files = ConfigurationManager.AppSettings["MaxUploadFileSizeMB"];

                if (String.IsNullOrEmpty(files))
                {
                    files = @"30";
                }

                return Convert.ToDouble(files);
            }
        }
        public static string BaseFolder
        {
            get
            {
                var files = ConfigurationManager.AppSettings["BaseFolder"];

                if (String.IsNullOrEmpty(files))
                {
                    files = @"C:\Temp\Article_attachments";
                }

                return files;
            }
        }

        public static string DefaultEmailSender
        {
            get
            {
                var defaultEmailSender = ConfigurationManager.AppSettings["DefaultEmailSender"];

                if (String.IsNullOrEmpty(defaultEmailSender))
                {
                    defaultEmailSender = "admin@e2a.com";
                }

                return defaultEmailSender;
            }
        }

        public static string ImageFileExtensions
        {
            get
            {
                var files = ConfigurationManager.AppSettings["ImageFileExtensions"];

                if (String.IsNullOrEmpty(files))
                {
                    files = "*.bmp|*.jpeg|*.png|*.gif|*.tif";
                }

                return files;
            }
        }

        public static string TextFileExtensions
        {
            get
            {
                var files = ConfigurationManager.AppSettings["TextFileExtensions"];

                if (String.IsNullOrEmpty(files))
                {
                    files = "*.txt|*.doc|*.docx";
                }

                return files;
            }
        }

        public static int PublicationMaxPageCount 
        {
            get 
            {
                var count = ConfigurationManager.AppSettings["PublicationMaxPageCount"];
                if (string.IsNullOrEmpty(count))
                {
                    count = "300";
                }

                return Convert.ToInt32(count);
            }
        }

        public static string DefaultLanguage
        {
            get
            {
                var path = ConfigurationManager.AppSettings["DefaultLanguage"];
                if (string.IsNullOrEmpty(path))
                {
                    path = "en-UK";
                }
                return path;
            }
        }

        public static string CachePath
        {
            get { return GetAppSetting("CachePath", "~/Cache/"); }
        }

        public static string LogType
        {
            get
            {
                var type = ConfigurationManager.AppSettings["LogType"];
                if (string.IsNullOrEmpty(type))
                {
                    type = "xml";
                }
                return type;
            }
        }

        public static string LogoPath
        {
            get
            {
                var path = ConfigurationManager.AppSettings["LogoPath"];
                if (string.IsNullOrEmpty(path))
                {
                    path = "~/Content/Images/banner";
                }
                return path;
            }
        }

        public static string NavBannerPath
        {
            get
            {
                var path = ConfigurationManager.AppSettings["NavBannerPath"];
                if (string.IsNullOrEmpty(path))
                {
                    path = "~/Content/Images/navbanner";
                }
                return path;
            }
        }
        

        public static string NavisionBackendUrl
        {
            get
            {
                var url = ConfigurationManager.AppSettings["NavisionBackendUrl"];
                if (string.IsNullOrEmpty(url))
                {
                    url = "http://svrnav.bordingvista.com.bd.local:7047/DynamicsNAV/WS/Bording A/S Test/Codeunit/NordicKLS.PPDS";
                }
                return url;
            }
        }

        public static string NavisionBackendUsername
        {
            get
            {
                var username = ConfigurationManager.AppSettings["NavisionBackendUsername"];
                if (string.IsNullOrEmpty(username))
                {
                    username = "nav";
                }
                return username;
            }
        }

        public static string NavisionBackendPassword
        {
            get
            {
                var password = ConfigurationManager.AppSettings["NavisionBackendPassword"];
                if (string.IsNullOrEmpty(password))
                {
                    password = "Mga4357";
                }
                return password;
            }
        }

        public static string NavisionBackendDomain
        {
            get
            {
                var domain = ConfigurationManager.AppSettings["NavisionBackendDomain"];
                if (string.IsNullOrEmpty(domain))
                {
                    domain = "SVRNAV";
                }
                return domain;
            }
        }

        public static double CacheDuration
        {
            get { return ConfigurationManager.AppSettings["CacheDuration"].ToDouble(1); }
        }
        public static string NhibernateConfigFile
        {
            get
            {
                var file = ConfigurationManager.AppSettings["NhibernateConfigFile"];
                if (string.IsNullOrEmpty(file))
                {
                    file = "hibernate.cfg.xml";
                }
                return file;
            }
        }

        public static string FtpRootPath
        {
            get
            {
                var FtpRootPath = ConfigurationManager.AppSettings["FtpRootPath"];
                if (string.IsNullOrEmpty(FtpRootPath))
                {
                    FtpRootPath = "";
                }
                return FtpRootPath;
            }
        }

        public static bool EmailFormatIsHtml
        {
            get
            {
                bool IsHtml = false;                
                try
                {
                    IsHtml = Convert.ToBoolean(ConfigurationManager.AppSettings["EmailFormatIsHtml"]);
                }
                catch
                {
                    IsHtml = false;
                }
                return IsHtml;
            }
        }
        
    }
}
